package com.platform.modules.mch.controller;

import com.alibaba.fastjson.JSONObject;
import com.platform.common.utils.RestResponse;
import com.platform.common.utils.ValidUtils;
import com.platform.common.utils.mch.config.MchConfig;
import com.platform.modules.mch.service.MchGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;

@Slf4j
@RestController
@RequestMapping("/mch/goods")
public class MchGoodsController {

    @Resource
    private MchGoodsService mchGoodsService;

    /**
     * 分页查询商品表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    public RestResponse list(@RequestParam HashMap<String, Object> params) {
        params.put("locationId", MchConfig.getLocationId());
        return RestResponse.success().put("page", mchGoodsService.list(new JSONObject(params)));
    }

    @PostMapping("/syncGoods")
    public RestResponse syncGoods(@RequestBody HashMap<String, Object> params) {
        ArrayList<String> ids = (ArrayList<String>)params.get("ids");
        String categoryId = (String) params.get("categoryId");
        ValidUtils.allNotNull(ids,categoryId);
        mchGoodsService.syncGoods(categoryId,ids);
        return RestResponse.success();
    }

}
